﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using ScFramework.Core;
using UnityEngine.UI;

public class TransformBarLogic : LogicModuleBase<UIManager>, ICombineSubUI
{
    GameObject target;
    List<MeshEntityData> currentEntity;
    MeshEntityData selected = null;
    public void InitGameobject(List<GameObject> obj)
    {
        target = obj.Find(s => s.name == "TransformBar");
        target.transform.Find("Flip").GetComponent<Button>().onClick.SetListener(Flip);
        target.transform.Find("Rotate").GetComponent<Button>().onClick.SetListener(Rotate);
        target.transform.Find("Delete").GetComponent<Button>().onClick.SetListener(Delete);
    }
    public override void OnEnable()
    {
        base.OnEnable();
        target.SetActive(true);
    }
    public override void OnDisable()
    {
        base.OnDisable();
        target.SetActive(false);
    }
    [RegisterEvent(CombineUIEvent.Receive_Data)]
    void Refresh(List<MeshEntityData> datas)//传入数据
    {
        currentEntity = datas;
    }


    [RegisterEvent(CombineUIEvent.ShowObjectValues)]
    void ChangeSelectedItem(int id)
    {
        if (id <= 0)
        {
            selected = null;
            return;
        }
        else
        {
            selected = currentEntity.Find(x => x.ID == id);
        }
    }


    private void Flip()
    {
        if (selected == null)
        {
            return;
        }//没选中返回
        Dispatch(CombineUIEvent.FlipEntity, selected.ID);
    }
    private void Rotate()
    {
        if (selected == null)
        {
            return;
        }
        Dispatch(CombineUIEvent.SpinEntity, selected.ID);
    }
    private void Delete()
    {
        if (selected == null)
        {
            return;
        }
        else
        {

            SysModule.Open("DialogWindowUI", 5, args: new DialogWindowUI.DialogWindowUIArg
 ("注意", "确定要删除物体吗", null, "确定", "取消", () =>
 {
     Dispatch(EntityDataReq.Delete,new EntityDeleteArgs(selected.ID));
 }));
        }
    }
}
